package com.yidu.BusinessData.service.impl;


import com.yidu.BusinessData.entity.CashEntity;
import com.yidu.BusinessData.mapper.CashMapper;
import com.yidu.BusinessData.service.CashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CashServiceImpl implements CashService {
    @Autowired
    private CashMapper cashMapper;

    /**
     * 添加现金账户
     * @param cash 账户类
     */

    @Override
    public void insertCash(CashEntity cash) {
        cashMapper.insertCash(cash);
    }

    @Override
    public List<CashEntity> selectCash(int page, int limit,CashEntity cashEntity) {
        Map map = new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("cashed",splicing(cashEntity));
        List<CashEntity> cashEntityList = cashMapper.selectCash(map);
        System.out.println(splicing(cashEntity)+"zheshi"+cashEntityList);
        return cashEntityList;

    }

    @Override
    public void deleteCash(String id) {
        cashMapper.deleteCash(id);
    }

    @Override
    public void updateCash(CashEntity cashEntity) {
        cashMapper.updateCash(cashEntity);
    }

    @Override
    public int CashCount(CashEntity cashEntity) {
        Map map = new HashMap();
        map.put("cashing",splicing(cashEntity));
        int i = cashMapper.CashCount(map);
        return i;
    }
    public String splicing(CashEntity cashEntity){
        StringBuffer str = new StringBuffer("");
        if (cashEntity.getCashType()!= 0){
            str.append(" and cashType = '"+cashEntity.getCashType()+" '");
        } if (cashEntity.getBankName()!= null && !cashEntity.getBankName().equals("")){
            str.append(" and bankName LIKE '%"+cashEntity.getBankName()+"%'");
        } if (cashEntity.getAccounName()!= null && !cashEntity.getAccounName().equals("")){
            str.append(" and bankAccount LIKE '%"+cashEntity.getBankAccount()+"% '");
        }
        return str.toString();
    }
}
